$(document).ready(function(){
	initNote();
	
});



//定义当前页数

var noteCurrentIndex;

function getNote(index){
	var url = "/HyperIT/note/findNote";
	var parm = "size=10&indexPageNum="+index;
	$.get(url,parm,function(data){
		if(data.serviceResult){
			console.log(data);
			var noteList = data.resultParm.note_list;
			showNote(noteList);
			noteCurrentIndex++;
		}else{
			alert(data.resultInfo);
		}
	});
}

function showNote(noteList){
	var str = '';
	for(var i = 0; i<noteList.length; i++){
		str+='<tr id="note_'+noteList[i].note.id+'"><td id="'+noteList[i].note.userDetail_id+'">'+noteList[i].user_name+'</td>';
		str+='<td>'+noteList[i].note.title+'</td>';
		str+='<td>'+noteList[i].note.createtime.split(".")[0]+'</td>';
		str+='<td><a href="noteDetail.html?userDetail_id='+noteList[i].note.userDetail_id+'&id='+noteList[i].note.id+'"><button>详 情</button></a><button onclick="delNote(this)">删 除</button></td></tr>';
	}
	$("#allNotes").append(str);
}

function getMoreNote(){
	getNote(noteCurrentIndex);
}

function initNote(){
	noteCurrentIndex = 1;
	getNote(noteCurrentIndex);
}

function delNote(which){
	var $thisNote;
	$thisNote = $(which).parent().parent();
	var id = $thisNote.attr("id").split("_")[1];
	var userdetail_id = $thisNote.children("td:first").attr("id");
	var msg = "确定要删除该随笔吗？";
		if (confirm(msg)==true){
			var url = "/HyperIT/note/deleteNote";
			var parm = "note_id="+id+"&userdetail_id="+userdetail_id;
			$.post(url,parm,function(data){
				if(data.serviceResult){
					$thisNote.remove();
					alert(data.resultInfo);
				}
				else{
					alert(data.resultInfo);
				}
			});
		}
		else{
		return false;
	}
}
